package frame.system.mapper;

import frame.system.qo.ConfQo;
import frame.system.to.ConfConverter;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 对应表：sys_conf_converter 对应实体类：ConfConverter
 * <br>
 * @author PeiWentao
 * @since 2020-09-24 11:24
 */
@Repository
public interface ConfConverterMapper extends Mapper<ConfConverter> {

	// 字段
    String FIELDS = "t.type,t.val,t.name,t.sorting,t.description,t.valid,t.create_time,t.update_time,t.id";
    // 表名 as 别名
    String TABLE = "sys_conf_converter t";
    // mapper包名
    String PACKAGE = "frame.system.mapper";

    @Results({
        @Result(column = "id", property = "id",id = true),
    })
    @Select({"<script>SELECT ", FIELDS, " FROM ", TABLE,
            " WHERE t.valid=${valid}",
            "<when test='type!=null'> AND type LIKE CONCAT(#{type},'%')</when>",
            " ORDER BY ${orderStr}",
            "</script>"})
	List<ConfConverter> pageList(ConfQo qo);

    @Select({"SELECT t.type,t.val,t.name,t.sorting,t.description,t.id FROM",
            TABLE,
            " WHERE t.valid=${valid}",
            " AND t.type =#{type}",
            " ORDER BY sorting ASC"
    })
    List<ConfConverter> selectList(ConfQo qo);

    @Select({"<script>SELECT count(*) FROM ", TABLE,
            "WHERE t.type=#{type} AND t.val=#{val}",
            "<when test='id!=null'> AND t.id !=#{id}</when>",
            "</script>"})
    int countTypeAndVal(ConfConverter convertor);
}
